local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.BaseComponent());
local ContextActionService = game:GetService("ContextActionService")
local LanguageHelper=_G.LanguageHelper --1:购买，2装备，3卸载
local GlobalTipGui = ClientOHOH.load.UIManager().ui_list.GlobalTipGui;
local Pet_Cfg=ClientOHOH.config.Pet
local Game_Cfg=ClientOHOH.config.Game
local PetTool=_G.CommonOHOH.load.PetTool();
local FunctionList = ClientOHOH.load.FunctionList();


local PetVoidGui = ClientOHOH.load.UIManager().ui_list.PetVoidGui
local event_manager = ClientOHOH.event_manager();
function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);
	self.currentBuySlot = nil
	self.DataBase=self.parent:GetComponent(ClientOHOH.load.Client_PlayerDataComponent());
	local data=self.DataBase:GetData("pets")
	------------虚空宠物--------------------
	
	PetVoidGui:SetDataBase(self.DataBase)
	--PetVoidGui:UpdateHad(data.had)
	self.player = self.parent
	self:UpdateVoidTime()

	PetVoidGui.VoidTimeGetEvent:Action( PetTool.GetVoidMakeTime(self.player))


	PetVoidGui.BuyEvent:Connect(function(data)
		--print("#### RobuxBuyEvent",data.gid,data.gType,data.petId,data.slotId,data)
		self.currentBuySlot = data.slotId
		--print("### BuyEvent:Connect",self.currentBuySlot,self)
		self.player.RobuxBuyEvent:Action(data.gid,data.gType)
	end)
	PetVoidGui.ReceiveEvent:Connect(function(timeId,slotId,hadBuy)
		--print("#### ReceiveEvent hadBuy",hadBuy)
		local isReceive = self.parent:Invoke(FunctionList.void_claim,timeId,hadBuy)
		if isReceive then
			PetVoidGui.ResetSlotEvent:Action(slotId)
		end

	end)
	PetVoidGui.CraftClickEvent:Connect(function(petId)
		local stime= self.parent:Invoke(FunctionList.void_craft,petId)
		PetVoidGui.UpdateSlotListEvent:Action(stime,PetVoidGui.voidTime,petId)
	end)
	
	
	self.player.RobuxBuyDoneEvent:Connect(function(gid,gtype)
		if gtype == "voidPetMake" then
			PetVoidGui.BuyDoneEvent:Action(self.currentBuySlot)
		end
	end)
	
	self.parent.UserDataEvent:Connect(function(data)
		if data["pets"] then
			PetVoidGui:UpdateHad(data["pets"].had)
		elseif data["gamePass"] then
			self:UpdateVoidTime()
			PetVoidGui.SCaleTimeUpdateSlotListEvent:Action(PetTool.GetVoidMakeTime(self.player))
		end
        
	end)

end

function M.UpdateVoidTime(self)
	local voidTime = PetTool.GetVoidMakeTime(self.player)
	PetVoidGui:SetVoidTime(voidTime)
	
end
function M.GetCurrentBuySlot(self)
	return  self.currentBuySlot
end
function M.dtor(self)
	M.super.dtor(self);
end
--event_manager:RegistHandle(ClientOHOH.event_list.server_player_voidbuy, function(self)
--	print("客户端收到购买完成的消息from slotCopy:",self.privateComponent.PetVoidCtrl)
--	PetVoidGui.BuyDoneEvent:Action(self.currentBuySlot)
--end)
  
return M

